import os
import xmmsclient.glib
from xmmsclient import XMMS
from gtk import *
from acover import CoverView
from playlist import Playlist
from player import Player

class UI(Window):
    def __init__(self, xmms2, actions_list):
        Window.__init__(self)
        cv = CoverView(xmms2)
        pl = Playlist(xmms2)
        player = Player(xmms2)
        self.connect("delete-event", lambda *args: main_quit())
        self.set_size_request(300, 200)
        vbox = VBox()
        self.add(vbox)
        ui = UIManager()
        accelgroup = ui.get_accel_group()
        self.add_accel_group(accelgroup)
        action = ActionGroup("UI")
        action.add_actions(actions_list)
        ui.insert_action_group(action, 0)
        ui.add_ui_from_file("playui.xml")
        menubar = ui.get_widget("/MenuBar")
        toolbar = ui.get_widget("/Toolbar")
        hbox = HBox()
        hbox.pack_start(cv)
        hbox.pack_start(pl)
        vbox.pack_start(menubar, False)
        vbox.pack_start(hbox)
        vbox.pack_start(player, False)
        vbox.pack_start(toolbar, False)
        self.show_all()
        pl.hbox.hide()
        pl.load_playlist()

    def play(self, *args):
        print "playing"


xmms2 = XMMS("player_manager")

try:
    xmms2.connect(os.getenv("XMMS_PATH"))
except Exception, e:
    print "could not connect", e
    exit(1)

xmmsclient.glib.GLibConnector(xmms2)

import actions
UI(xmms2, actions.actions_list)
main()
